//泛型函数
function logData<T>(data: T) {
    console.log(data)
}

logData<string>('1')
logData<number>(2)

// 泛型可以多个
function logData1<T, U>(data1: T, data2: U): T | U {
    return Date.now() % 2 ? data1 : data2
}

logData1<number, boolean>(100, true)
logData1<string, number>('hello', 666)

// 泛型接口
interface PersonInterface<T> {
    name: string,
    age: number,
    extraInfo: T
}

let p: PersonInterface<number> = {
    name: 'tom',
    age: 10,
    extraInfo: 10
}

type JobInfo = {
    title: string,
    company: string
}

let p1: PersonInterface<JobInfo> = {
    name: 'tom',
    age: 10,
    extraInfo: {
        title: '1',
        company: '2'
    }
}